YouTube URL "Detector" (v.8)

By Kirby on Mar 27, 2009

This was actually ^Neptune's request, so here it is.

YouTube! When you're chatting with your friends on IRC, you'll usually encounter some YouTube links to videos. But ever wonder what the video is? Instead of opening a new tab in your browser to see actually "what" it is, you can have a personal YouTube URL Detector.

Just load it onto a bot, put a YouTube URL, and it'll give you information on the following:

  • Title of the video Uploader's name Date uploaded Duration of the video Number of views* Rating + Number of Ratings:)

[size=16]Newer news[/size]
[size=14]Updates![/size]: I've removed the TinyURL edition for specific reasons, mentioned below. I might post a snippet on it later, but it will not be in this snippet. (If you liked the older version and enjoyed the benefit of downloading the videos, check out the older version here.
I've also enhanced the speed of the script, removed the use of key identifiers such as $between and $htmlfree, and reduced script space. Triple the pleasure?

[size=16]Older news[/size]

If you do not like the new update: > Some of you might say that the TinyURL links do not work, or it leads to a blank page and halts.
"It is most likely because it is a .flv file and/or unknown to the web browser."

[size=14]Edit[/size]: That is false. I've later realized that the URL is actually user-based, essentially only one person can access it, or the bot owner; the owner sockopens to the YouTube site, and therefore, given a specific code that expires when accessed.

Despite the update, I doubt many will be intrigued to even download a certain YouTube video (if you can stream it online, why download it?), so I'm not worried much.
Otherwise, the TinyURL's should work if the selected browser detects it.
If your browser happens to detect the video, the video name should be called video.flv.

If you find any bugs, let me know!

Here's a picture:
Image

If you can't see the picture:

<@noob> http://www.youtube.com/watch?v=eghL7ORV1lg
<@null> [YouTube]: Title: Seinfeld - Million to One Shot Doc | By: NIGathan (uploaded on August 12, 2008) | Duration: 2mins 8secs | Views: 7,573 | Rating: 4.5 (11 ratings)

Here's the other picture:
Image

If you can't see the picture:

<@noob> http://www.youtube.com/watch?v=eghL7ORV1lg
<@null> [YouTube]: Title: Seinfeld - Million to One Shot Doc | By: NIGathan (uploaded on August 12, 2008) | Duration: 2mins 8secs | Views: 7,573 | Rating: 4.5 (11 ratings) | Download: http://tinyurl.com/dem5lq (http://preview.tinyurl.com/dem5lq)

Updates:
Update #1 - Sat Mar 27, 11:32 AM: Fixed the bug with the "duration" with ^Neptune's $between.
Update #2 - Sat Mar 28, 11:47 AM: Added error checks to see if the video exists or not.
Update #3 - Sun Mar 29, 11:36 AM: Fixed minor bug (if ratings on the video are disabled).
Update #4 - Tue Mar 31, 6:25 PM: Fixed bug where it gets text after the video url. Thanks to Jonesy44 for the regex help.
Update #5 - Mon Apr 13, 9:33 PM: Added TinyURL link to direct link to the YouTube Video, for downloading. (.flv file called video.flv)

Enjoy! :D

;SOF

;~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*;
;             YouTube Video "Detector"           ;
;             Made by Kirby (Quakenet)           ;
;*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~;

;// YouTube Detector Identifiers //
alias -l addmark { return $+($sock($1).mark,$chr($3),$2) }
alias -l smsg { msg $iif(c isincs $chan($1).mode,$1 $strip($2-),$1-) }

;// YouTube Detector Text Event //
on *:text:*youtube.com/watch?v=*:#: {
  if (!$sock(youtube)) {
    noop $regex($strip($1-),http:\/\/.*youtube.*\/watch\?v=(.{11})&?.*)
    sockopen youtube www.youtube.com 80 | sockmark youtube $+(#,>,$regml(1))
  }
}

;// YouTube Detector Socket (Video Information) //
on *:sockopen:youtube: {
  sockwrite -n $sockname GET $+(/watch?v=,$gettok($sock(youtube).mark,2,62)) HTTP/1.0
  sockwrite -n $sockname Host: www.youtube.com
  sockwrite -n $sockname $crlf
}
on *:sockread:youtube: {
  var %x | sockread %x
  if ($regex(%x,<meta\sname="title"\scontent="(.+)">)) sockmark youtube $addmark(youtube,Title: $+(,$regml(1),),62)
  elseif ($regex(%x,"length_seconds":\s"(\w+)")) sockmark youtube $addmark(youtube,Duration: $+(,$duration($regml(1)),),62)
  elseif ($regex(%x,title="(.+)">.+<span\sclass="smallText">(.+)\sratings<\/span>)) sockmark youtube $addmark(youtube,$+($regml(1),>,$regml(2)),62)
  elseif ($regex(%x,view-count">(.+)<\/span>\s)) { sockmark youtube $addmark(youtube,$regml(1),62) }
  elseif ($regex(%x,date">(.+)<\/span>)) sockmark youtube $addmark(youtube,$+($chr(40),uploaded on $regml(1),$chr(41)),62)
  elseif ($regex(%x,<a\sclass="url"\shref="\/user\/(\w+)")) sockmark youtube $addmark(youtube,By: $+(,$regml(1),),62)
}
on *:sockclose:youtube: {
  tokenize 62 $sock(youtube).mark | var %x $numtok($sock(youtube).mark,62)
  smsg $1 [1,0You0,4Tube]: $iif(%x >= 7,$3 $chr(124) $5 $6 $chr(124) $4 $chr(124) Views: $+(,$iif(%x == 7,$7,$9),) $chr(124) Rating: $iif(%x == 9,$+(,$7,) $+($chr(40),$8 $iif($8 == 1,rating,ratings),$chr(41),),$+(,Ratings were disabled,)),Either the video doesn't exist or it contained a malformed video ID.)
}

;EOF

Comments

Sign in to comment.
BeginnerS   -  Dec 12, 2015

Either the video doesn't exist or it contained a malformed video ID.
This is what I get ....after the [YouTube]:Either the video doesn't exist or it contained a malformed video ID.

Sidearm  -  Dec 12, 2015

No shit, it's almost six years old, YouTube's layout has changed so much it won't work at all.

Sign in to comment

cptpan   -  May 10, 2014

Yeah this script is proper fukd now.

 Respond  
chachin   -  May 04, 2012

the hell is all this :(

[5:55:44pm] <@chachin> http://www.youtube.com/watch?v=lVefgfmFg9o
[5:55:45pm] <@chick3n> [YouTube]: Title: Hand back into the Large Hadron Collider - Sixty Symbols | <span class="stat" by <span class="yt-user-name " dir="ltr" | (uploaded on Man Returns Phone To Best Buy, Gets 'Gay' Facebook Update</span | Views: <span class="stat" | Rating: Ratings were disabled

 Respond  
Callvote   -  Jul 30, 2011

What and how to write to me to not only write off a hit, but everyone can see it?

 Respond  
H0LLYWOOD   -  Jul 15, 2011

hey guys. i asked Ford_Lawnmower to look into updating this a couple days ago. and he did us the favor of making a updated script.
heres the url: http://www.hawkee.com/snippet/8814/

 Respond  
JoKabua   -  Jul 15, 2011

Why it doesn't load on me?

[17:53] http://www.youtube.com/watch?v=RM-ndYlWTcY&feature=player_embedded#at=12
[17:53] [1,0You0,4Tube]: Either the video doesn't exist or it contained a malformed video ID.

 Respond  
Donovan   -  May 07, 2011

Hey has this been working for anybody?

 Respond  
bahiense   -  Jan 18, 2011

yeah , i knoe is strange , for some videos works , for others no , youtube change stuff all the time so i guess depends on when the video was uploaded too ...

 Respond  
sunslayer   -  Jan 08, 2011

@KillerX youtube's source is changed so often its difficult to keep up with it

 Respond  
KilllerX   -  Jan 08, 2011

um... yah

Same as dreamlord

@Killlerx: http://www.youtube.com/watch?v=5GMMB73oiLs
@Killlerbotx: [YouTube]: Either the video doesn't exist or it contained a malformed video ID.

 Respond  
TheDreamLord   -  Jan 08, 2011

Nope doesnt work...http://www.youtube.com/watch?v=EpbmMhNe6aA

[YouTube]: Either the video doesn't exist or it contained a malformed video ID.
 Respond  
Bielie   -  Dec 03, 2010

oke Thanks ;) Please put that link in the upper post ;)

 Respond  
bahiense   -  Nov 30, 2010

[23:26:40] 09@j_bot [YouTube] Title: [HD] Cortland Finnegan and Andre Johnson Fight! (ALL CAMERA ANGLES)! <> Comments: 2,168 <> Favorites: 903 <> Total Views: 446,048 <> Ratings: 646 <> Likes: 620 <> Dislikes: 26

 Respond  
bahiense   -  Nov 30, 2010

Bielie , here http://www.hawkee.com/phpBB2/viewtopic.php?t=22062&highlight=youtube , Jethro_ come up with a solution :) ( youtube likes to change everything from time to time :) )

 Respond  
Bielie   -  Nov 30, 2010

Outdated.. Gives errors on any link

 Respond  
Lucius   -  Oct 08, 2010

works fine for me...

«Fri-12:38pm» http://www.youtube.com/watch?v=eghL7ORV1lg
«Fri-12:38pm» [YouTube] "Seinfeld - Million to One Shot Doc" --- 14,237 views ( 20 likes, 2 dislikes ) uploaded by NIGathan

Might have been that youtube was taking too long to respond, or you had some other connection trouble between the bot and the site. Unless you have altered the code and it no longer works.

 Respond  
airsfotglock   -  Oct 07, 2010

errm this script doent work i used the exact same url from the example and it said this
<~airsoftglock> http://www.youtube.com/watch?v=eghL7ORV1lg

[YouTube]: Either the video doesn't exist or it contained a malformed video ID.
 Respond  
PsyTrance   -  Aug 03, 2010

Oh :(
I watch source code and all time is for related videos, you are right.

Thank You anyway!!

 Respond  
bahiense   -  Aug 03, 2010

sorry PsyTrance , i can't help with that one , i tried , but seems the duration of the video is not in the html source code ( from where the script reads to search everything , go to any video and in your browser check the source code , search the time and you will see is not there ; all the durations i can see are from the related videos but no the playing one :( ) , i tried with several videos , seems like the duration is embedded in some way in the flash player and not in the html itself , maybe someone else with more experience in scripting can help us with that :)

PS : i add something i found :) i replaced
title="(.+)"> )) set %youtuberating $regml(1)

with
title="(.+)">)) set %youtuberating $regml(1)

only deleted the space after title="(.+)"> , in some videos was not working right

 Respond  
PsyTrance   -  Aug 03, 2010

@bahiense: This script work perfect! But missing duration of video. Can you or someone add this line for duration? I'm total beginer in mIRC scripting.

(sorry for bad english, i hope you understand :))

Thank You!

 Respond  
Lucius   -  Jul 25, 2010

That's because the sock events are completely seperate to the trigger.
You can tell because of the completely closed { brackets } you have either

on *:event { 

OR

alias etc { 

starting the next section so it's an internal run part of the script and doesn't have an $chan to send to.

 Respond  
bahiense   -  Jul 23, 2010

exactly , for some reason ( kind of noob to this still so idk why , actually this one was my firs or second script using sockets :) ) , the $chan doesnt work within the sockclose event , so you need to use the actual name of the channel ( #blabla , if you have only 1 ) or a variable like lucius said :)

 Respond  
Lucius   -  Jul 23, 2010

add a line after

on *:text:*youtube.com/watch?v=*:#: {
 set %tubechan $chan

then msg %tubechan etc etc

btw thanks for the update, it works a treat.

 Respond  
RicJames   -  Jul 23, 2010

Thanks for this bahiense, just one question how do I change this to work on all chans? I tried changing msg #CHANNEL to msg $chan but it didn't work.

 Respond  
bahiense   -  Jul 21, 2010

UPDATED 2 DECEMBER 2010
here http://www.hawkee.com/phpBB2/viewtopic.php?t=22062&highlight=youtube , Jethro_ come up with a solution :)


this one works ( USED TO , i keep it here just in case) ( just my small adaptation of the original here ) :)

; ********** YOUTUBE ****************************
on *:text:*youtube.com/watch?v=*:#: {
  if (!$sock(youtube)) {
    noop $regex($strip($1-),http:\/\/.*youtube.*\/watch\?v=(.{11})&?.*)
    sockopen youtube www.youtube.com 80 | sockmark youtube $+(#,>,$regml(1))
  }
}

on *:sockopen:youtube: {
  sockwrite -n $sockname GET $+(/watch?v=,$gettok($sock(youtube).mark,2,62)) HTTP/1.0
  sockwrite -n $sockname Host: www.youtube.com
  sockwrite -n $sockname $crlf
}

on *:sockread:youtube: {
  var %x | sockread %x
  if ($regex(%x,<meta name="title" content="(.+)">))  set %youtubetitle $regml(1)
  elseif ($regex(%x,<strong class="watch-view-count">(.+)</strong><br>))  set %youtubeviews $regml(1)
  elseif ($regex(%x,<span class="watch-video-date">(.+)</span>))  set %youtubedate $regml(1)
  elseif ($regex(%x,<div class="action-bar-ratings-stats yt-uix-tooltip" title="(.+)"> ))  set %youtuberating $regml(1)
  elseif ($regex(%x,<a id="watch-username" class="inline-block" href="/user/(.+)">))  set %youtubeuser $regml(1)
}

on *:sockclose:youtube: {
  msg #CHANNEL $chr(91) $+ YouTube $+ $chr(93) " $+ %youtubetitle $+ " --- %youtubeviews views $& 
    ( %youtuberating ) uploaded %youtubedate by %youtubeuser ---
  unset %youtube*
}
; ************************************************

[14:52:16] http://www.youtube.com/watch?v=wnNhxqD1FTA
[14:52:18] [YouTube] "That's the Thing about Football 2008" --- 14,602 views ( 33 likes, 1 dislikes ) uploaded by TheSwert ---

just change the name of your channel in
on *:sockclose:youtube

 Respond  
RicJames   -  Jun 19, 2010

You've seen them scripts, but that doesn't mean you can get them. Unless, of course, the people who own 'em are generous enough to give you a copy. From my own experience, people who own something good will rather keep it to themselves, though...'cause they don't want other folks to have what they got distributed all over the place. This is sort of like a secret family recipe saying: if I told you, I'd have to kill you. Don't get me wrong on that matter...there's still a chance, but it's not that great.

Unfortunately a lot of people like that exist. The thing they don't realise is what goes around comes around.

 Respond  
Exterus   -  Jun 18, 2010

There are working ones for eggdrop bots and irssi available. Just not for mirc.

 Respond  
Jethro   -  Jun 18, 2010

You've seen them scripts, but that doesn't mean you can get them. Unless, of course, the people who own 'em are generous enough to give you a copy. From my own experience, people who own something good will rather keep it to themselves, though...'cause they don't want other folks to have what they got distributed all over the place. This is sort of like a secret family recipe saying: if I told you, I'd have to kill you. Don't get me wrong on that matter...there's still a chance, but it's not that great.

 Respond  
cptpan   -  Jun 18, 2010

I've seen them working on networks so people can get them, or have them or have made them!

 Respond  
RicJames   -  Jun 18, 2010

Where? I haven't seen any.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.